<?php 
/**
 * 产品展示介绍model
 * @author Administrator
 *
 */
class ProductModel extends Model
{
	//数据表
	protected $trueTableName = 'td_product';
	
	//设置主键
	protected  $key = 'td_id';


	//自定义获取数量
    public function getAllcont($seek='')
    {

        $results = M('new_ytd')->where($seek)->count();;
        return $results;
    }

    //自定义获取全部
    public function getAllnr($page, $seek='')
    {

        //P($seek);
        //关联console查询
        if ( $page == '' )
        {
            $results = M('new_ytd')->order('sort desc')->where($seek)->select();

        }
        else
        {
            $results = M('new_ytd')->order('sort desc')->where($seek)->limit($page)->select();

        }

        return $results;
    }




	//获取数据条数
	public function getCount($seek='')
	{
	
			
		//设置左表
		$rightTable = 'ty_type as T';
			
		$this->trueTableName = 'td_product as Y';
			
		//条件
		$where = 'Y.td_id > 0';
		$on = 'Y.ty_id = T.ty_id';

		$results = $this->join('RIGHT JOIN '.$rightTable.' ON '.$on)->where($seek.$where)->count();

		//恢复原表名
		$this->trueTableName = 'td_product';
	
		return $results;
	
	}
	/**
	 * 获取列表
	 * @param unknown $page 分页参数
	 * @param unknown $seek 搜索参数
	 * @return Ambigous <mixed, string, boolean, NULL, unknown, multitype:, multitype:multitype: , void, object>
	 */
	public function getListAll($page, $seek='')
	{
		//设置右表
			$rightTable = 'ty_type as T';
				
			$this->trueTableName = 'td_product as Y';
				
			//字段
			$field = array(
					
					'*',
					
			);
				
			//条件
			$where = 'Y.td_id > 0';
				
			$on = 'Y.ty_id = T.ty_id';
				
			//关联console查询
			if ( $page == '' )
			{
				$results = $this->field($field)->join('RIGHT JOIN '.$rightTable.' ON '.$on)->order('sort desc')->where($seek.$where)->select();
			}
			else
			{
				$results = $this->field($field)->join('RIGHT JOIN '.$rightTable.' ON '.$on)->order('sort desc')->where($seek.$where)->limit($page)->select();
			}
				
			//恢复原表名
			$this->trueTableName = 'td_product';
				
			return $results;
	}
	/**
	 * 插入一条数据
	 * @param array $data
	 * @return Ambigous <mixed, boolean, string, false, number>
	 */
	public function insert(array $data)
	{


		//字段
		$field = array(
				'td_id',
				'td_name',
				'base_img',
				'td_text',
				'sort',
                'add_time',
				'td_content',
				'ty_id',
                 'is_show',
		);

		//字段过滤
		$data = $this->CheckField($data, $field);

	
		return $this->add($data);
			
	}
	/**
	 * 更新一条数据
	 */
	public function update(array $data, $id)
	{
	
		//字段
		$field = array(
				'td_name',
				'base_img',
                'add_time',
				'td_text',
				'sort',
				'td_content',
				'ty_id',
                 'is_show',
		);
	
		//字段过滤
		$data = $this->CheckField($data, $field);
	
		//条件
		$where = $this->key.'='.$id;
			
	
		return $this->where($where)->save($data);
	
	}
	/**
	 * 获取团队信息
	 * @param unknown $id
	 * @return Ambigous <mixed, boolean, NULL, multitype:, unknown, string>
	 */
	public function getRowById($id)
	{
		//字段
		$field = array(
				'*',
	
		);
	
		//条件
		$where = $this->key."=".$id;
	
		return $this->field($field)->where($where)->find();
	}
	/**
	 * 删除控制
	 * @param unknown $id
	 * @return Ambigous <mixed, boolean, false, number>
	 */
	public function del($id)
	{
			
		//单选
		if ( !is_array($id) )
		{
	
			return $this->delete($id);
		}
		//多选
		else
		{
	
			$idStr = implode(',', $id);
			//die($idStr);
			return $this->where("td_id in (".$idStr.")")->delete();
	
		}
			
	}
}


?>